#@layout()

#define content()

<div id="datagridId"></div>

<div id="datagridTb">
    <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" id='zone_add'>增加区域</a>
    <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
       id='zone_remove'>删除区域</a>
    <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
       id='file_box_detail'>查看详情</a>
</div>
#end


#define css()

#end


#define js()
<script type="text/javascript">
    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/zoneList';

    $(function () {

        //初始化表格
        $("#" + _datagrid).datagrid({
            title: '文件管理',
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 30,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            columns: [[
                {field: 'zone_id', title: 'zone_id', width: 100, checkbox: true},
                {
                    field: 'zone_name',
                    title: "区域名称"
                },
                {
                    field: 'delete_time',
                    title: "删除时间"
                },
                {
                    field: 'retain_days',
                    title: "保留天数"
                },
                {
                    field: 'is_finish',
                    title: "是否完成",
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '已完成';
                        } else {
                            return '未完成';
                        }
                    }
                },
                {
                    field: 'setting_time',
                    title: "设置时间"
                }
            ]]
        });


        $("#zone_add").on('click', function () {
            var params = {};
            params.title = "增加文件";
            params.width = 800;
            params.height = 400;
            params.top = '10px';
            params.modal = true;
            params.iconCls = 'icon-save';
            params.url = contextRootPath + '/zoneAdd';
            params.buttons = [{
                text: '提交',
                iconCls: 'icon-ok',
                handler: function () {
                    datagrid_save('add');
                }
            }, {
                text: '重置',
                iconCls: 'icon-cancel',
                handler: function () {
                    clearForm('zoneFormId');
                }
            }];

            crud_dlg(params);
        });


        $("#zone_remove").on('click', function () {
            var selections = $('#' + _datagrid).datagrid('getSelections');
            var ids = "";

            if (selections.length < 1) {
                $.messager.alert("提示框", "请选择需要操作的区域!", "warning");
                return;
            }

            $.messager.confirm('确认框', '请确定需要删除所选择的区域么？', function (r) {
                if (r) {
                    $.each(selections, function (i, v) {
                        ids += v['zone_id'] + ",";
                    });

                    $.post(contextRootPath + "/zoneRemove/" + ids, function (data) {
                        var params = {};
                        params.element = _datagrid;
                        params.data = data;
                        params.isClose = false;
                        resultCallback(params);
                    }, 'json');
                }
            });
        });


        $("#file_box_detail").on('click', function () {
            var selected = $('#' + _datagrid).datagrid('getSelected');


            if (selected == null) {
                $.messager.alert("提示框", "请选择需要操作的文件!", "warning");
                return;
            }

            var selections = $('#' + _datagrid).datagrid('getSelections');

            if (selections.length < 1) {
                $.messager.alert("提示框", "请选择需要操作的文件!", "warning");
                return;
            } else if (selections.length > 1) {
                $.messager.alert("提示框", "选择的文件为多个，请重新选择!", "warning");
                return;
            }

            location.href = contextRootPath + "/fileBox/" + selected.zone_id;
        });

    });

</script>

#end